import plugin from '../../../lib/plugins/plugin.js';
import common from '../../../lib/common/common.js';

export class wzry extends plugin {
	constructor() {
		super({
			name: '[Xs插件]王者荣耀查战力',
			dsc: '王者荣耀查战力',
			event: 'message',
			priority: 9,
			rule: [
			{
				reg: '^#?查战力安卓QQ(.*)$',
				fnc: `wzryaqq`
			},
			{
				reg: '^#?查战力安卓微信(.*)$',
				fnc: `wzryawx`
			},
			{
				reg: '^#?查战力苹果QQ(.*)$',
				fnc: `wzryiqq`
			},
			{
				reg: '^#?查战力苹果微信(.*)$',
				fnc: `wzryiwx`
			},
			{
				reg: '^#?战力查询帮助$',
				fnc: `wzrybz`
			}
			]
		})
	}

	async wzryaqq (e) {
		if (/#?查战力安卓QQ/.test(e.msg)) {
	   	  e.msg = e.msg.replace(/#?查战力安卓QQ/g, '');
	   	  let msg = e.msg;
	   	  let name = msg;
	   	  let type = 'aqq';
	   	  if (!name) {
		   		e.reply(`请输入需要查询的英雄名字`,true);
		   		return true;
	   	  } else {
	   	  	let geturl = `https://api.lolimi.cn/API/wangzhe/?name=${name}&type=${type}&mos=text`;
	   	  	let res = await fetch(geturl);
	   	  	res = await res.text();
	   	  	if (res.includes('错误')) {
	   	  		e.reply(`查询失败,${res}`,true);
		   		return true;
	   	  	} else {
	   	  		e.reply(`查询成功,${res}`,true);
		   		return true;
	   	  	}
	      }
	  }
   }

   async wzryawx (e) {
   		if (/#?查战力安卓微信/.test(e.msg)) {
	   	  e.msg = e.msg.replace(/#?查战力安卓微信/g, '');
	   	  let msg = e.msg;
	   	  let name = msg;
	   	  let type = 'awx';
	   	  if (!name) {
		   		e.reply(`请输入需要查询的英雄名字`,true);
		   		return true;
	   	  } else {
	   	  	let geturl = `https://api.lolimi.cn/API/wangzhe/?name=${name}&type=${type}&mos=text`;
	   	  	let res = await fetch(geturl);
	   	  	res = await res.text();
	   	  	if (res.includes('错误')) {
	   	  		e.reply(`查询失败,${res}`,true);
		   		return true;
	   	  	} else {
	   	  		e.reply(`查询成功,${res}`,true);
		   		return true;
	   	  	}
	      }
	  }
   }

   async wzryiqq (e) {
   		if (/#?查战力苹果QQ/.test(e.msg)) {
	   	  e.msg = e.msg.replace(/#?查战力苹果QQ/g, '');
	   	  let msg = e.msg;
	   	  let name = msg;
	   	  let type = 'iqq';
	   	  if (!name) {
		   		e.reply(`请输入需要查询的英雄名字`,true);
		   		return true;
                } else {
	   	  	let geturl = `https://api.lolimi.cn/API/wangzhe/?name=${name}&type=${type}&mos=text`;
	   	  	let res = await fetch(geturl);
	   	  	res = await res.text();
	   	  	if (res.includes('错误')) {
	   	  		e.reply(`查询失败,${res}`,true);
		   		return true;
	   	  	} else {
	   	  		e.reply(`查询成功,${res}`,true);
		   		return true;
	   	  	}
	      }
	  }
   }

   async wzryiwx (e) {
   		if (/#?查战力苹果微信/.test(e.msg)) {
	   	  e.msg = e.msg.replace(/#?查战力苹果微信/g, '');
	   	  let msg = e.msg;
	   	  let name = msg;
	   	  let type = 'iwx';
	   	  if (!name) {
		   		e.reply(`请输入需要查询的英雄名字`,true);
		   		return true;
	   	  } else {
	   	  	let geturl = `https://api.lolimi.cn/API/wangzhe/?name=${name}&type=${type}&mos=text`;
	   	  	let res = await fetch(geturl);
	   	  	res = await res.text();
	   	  	if (res.includes('错误')) {
	   	  		e.reply(`查询失败,${res}`,true);
		   		return true;
	   	  	} else {
	   	  		e.reply(`查询成功,${res}`,true);
		   		return true;
	   	  	}
	      }
	  }
   }

   async wzrybz(e) {
   		e.reply('示例：#查战力安卓QQ李信',true)
   		return true;
   }
}